package cn.iocoder.yudao.module.system.controller.admin.userdetail;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.userdetail.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.userdetail.UserDetailDO;
import cn.iocoder.yudao.module.system.convert.userdetail.UserDetailConvert;
import cn.iocoder.yudao.module.system.service.userdetail.UserDetailService;

@Tag(name = "管理后台 - 艾灸师详情")
@RestController
@RequestMapping("/system/user-detail")
@Validated
public class UserDetailController {

    @Resource
    private UserDetailService userDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建艾灸师详情")
    @PreAuthorize("@ss.hasPermission('system:user-detail:create')")
    public CommonResult<Long> createUserDetail(@Valid @RequestBody UserDetailCreateReqVO createReqVO) {
        return success(userDetailService.createUserDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新艾灸师详情")
    @PreAuthorize("@ss.hasPermission('system:user-detail:update')")
    public CommonResult<Boolean> updateUserDetail(@Valid @RequestBody UserDetailUpdateReqVO updateReqVO) {
        userDetailService.updateUserDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除艾灸师详情")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:user-detail:delete')")
    public CommonResult<Boolean> deleteUserDetail(@RequestParam("id") Long id) {
        userDetailService.deleteUserDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得艾灸师详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:user-detail:query')")
    public CommonResult<UserDetailRespVO> getUserDetail(@RequestParam("id") Long id) {
        UserDetailDO userDetail = userDetailService.getUserDetail(id);
        return success(UserDetailConvert.INSTANCE.convert(userDetail));
    }

    @GetMapping("/list")
    @Operation(summary = "获得艾灸师详情列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('system:user-detail:query')")
    public CommonResult<List<UserDetailRespVO>> getUserDetailList(@RequestParam("ids") Collection<Long> ids) {
        List<UserDetailDO> list = userDetailService.getUserDetailList(ids);
        return success(UserDetailConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得艾灸师详情分页")
    @PreAuthorize("@ss.hasPermission('system:user-detail:query')")
    public CommonResult<PageResult<UserDetailRespVO>> getUserDetailPage(@Valid UserDetailPageReqVO pageVO) {
        PageResult<UserDetailDO> pageResult = userDetailService.getUserDetailPage(pageVO);
        return success(UserDetailConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出艾灸师详情 Excel")
    @PreAuthorize("@ss.hasPermission('system:user-detail:export')")
    @OperateLog(type = EXPORT)
    public void exportUserDetailExcel(@Valid UserDetailExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<UserDetailDO> list = userDetailService.getUserDetailList(exportReqVO);
        // 导出 Excel
        List<UserDetailExcelVO> datas = UserDetailConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "艾灸师详情.xls", "数据", UserDetailExcelVO.class, datas);
    }

}
